<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>Shorten Link</title>
	
	<link rel="stylesheet" href="utilitywindow.css" type="text/css" media="screen" title="no title" charset="utf-8">
	<script src="app:/assets/air/AIRAliases.js" type="text/javascript" charset="utf-8"></script>
	<script src="app:/assets/jquery/jquery.js" type="text/javascript" charset="utf-8"></script>
	<script src="app:/assets/spaz/spaz.js" type="text/javascript" charset="utf-8"></script>	
	<script src="app:/assets/spaz/spaz.debug.js" type="text/javascript" charset="utf-8"></script>
	<script src="app:/assets/spaz/spaz.sys.js" type="text/javascript" charset="utf-8"></script>
	<script src="app:/assets/spaz/spaz.shortlink.js" type="text/javascript" charset="utf-8"></script>
	<script src="app:/assets/lib/webtoolkit.trim.js" type="text/javascript" charset="utf-8"></script>
	
	<script type="text/javascript" charset="utf-8">
		Spaz.Prefs = window.opener.Spaz.Prefs;
	</script>
	
	<script type="text/javascript" charset="utf-8">
		$(document).ready(function() {

			// get the pref
			var service = Spaz.Prefs.get('url-shortener');
			air.trace("service is "+ service);
			
			// populate the dropdown
			for (method in Spaz.Shortlink.services) {
				air.trace(method)
				if (method[0] != '$') {
					if (method == service) {
						$('#url-shortener').append('<option value="'+method+'" selected="selected">'+method+'</option>');
					} else {
						$('#url-shortener').append('<option value="'+method+'">'+method+'</option>');
					}
				}
			}
			
			$('#url-shortener').bind('change', function() {
				air.trace($('#url-shortener').val());
				Spaz.Prefs.set('url-shortener', $('#url-shortener').val());
			});
			

			
			// Spaz.dump("val:"+$('#shorten-original-link').val());
			$('#shorten-original-link').focus();
			$('#shorten-original-link').val('http://');
			// Spaz.dump(air.Clipboard.generalClipboard.formats);
			if(air.Clipboard.generalClipboard.hasFormat(air.ClipboardFormats.TEXT_FORMAT)) {
			    var cliptext = air.Clipboard.generalClipboard.getData(air.ClipboardFormats.TEXT_FORMAT);
				if (/^https?:\/\//.test(cliptext)) { // if it starts with http://, we assume this is an URL and put it in the form field
					$('#shorten-original-link').val(cliptext);
					Spaz.Shortlink.services[service](cliptext);
				}
				$('#shorten-original-link').select();
			}
			
			
			// bind click to shorten action
			$('#prefs-update-button').bind('click', function() {
				var service = Spaz.Prefs.get('url-shortener');
				air.trace("service is "+ service);
				Spaz.Shortlink.services[service]($('#shorten-original-link').val());
			});
			
			// air.trace(air.NativeApplication.nativeApplication.spazPrefs);
		})
	</script>
	
	
</head>

<body id="shortLinkWindow">

<h1>Shorten Link</h1>

<div id="content">
	<form id="shortenLink-form" onsubmit="return false;">
		<div class="formrow">
			<label for="url-shortener">Service</label>
			<select id="url-shortener" name="url-shortener" onChange="">
				<!-- stuff goes here -->
			</select>
		</div>

		<div class="formrow">
			<label for="original-link">Link</label>
			<input type="text" name="original-link" id="shorten-original-link" value="http://" />
		</div>
		<div class="formrow">
			<label for="short-link">Short</label>
			<input type="text" name="short-link" id="shorten-short-link" value="" />
		</div>
		
		<div class="formrow" style="text-align:right; margin-top:15px">
			<input type="button" id="prefs-update-button" name="update" value="Shorten &bull;" /> 
		</div>
		<div id="verification-result" align="center">&nbsp;</div>
	</form>
</div>
</div>

</body>
</html>
